package rents.internal;

import java.util.HashMap;
import java.util.Map;

import org.springframework.orm.ObjectRetrievalFailureException;

import rents.User;
import rents.internal.account.Account;
import rents.internal.local.BenefitAvailabilityPolicy;
import rents.internal.local.Local;
import rents.internal.local.LocalRepository;

import common.money.Percentage;

public class StubLocalRepository implements LocalRepository{
	
	private Map<String, Local> localsByMerchantNumber = new HashMap<String, Local>();

	public StubLocalRepository() {
		Local local = new Local("1234567890", "Apple Bees");
		local.setBenefitPercentage(Percentage.valueOf("8%"));
		local.setBenefitAvailabilityPolicy(new AlwaysReturnsTrue());
		localsByMerchantNumber.put(local.getNumber(), local);
	}

	public Local findByMerchantNumber(String merchantNumber) {
		Local local = (Local) localsByMerchantNumber.get(merchantNumber);
		if (local == null) {
			throw new ObjectRetrievalFailureException(Local.class, merchantNumber);
		}
		return local;
	}

	
	public static class AlwaysReturnsTrue implements BenefitAvailabilityPolicy {
		public boolean isBenefitAvailableFor(Account account, User user) {
			return true;
		}
	}
	
	
	
	

}
